import {
  Access,
  GateGrantGateway,
  doRiverStockeGrantDto,
  doRiverVoucherGroupGrantDto,
  doRiverTonOrderGroupGrantDto,
  GateGrantInterfaceWithPrimary,
} from "qqlx-core";

import { ViewBase } from "@view/view-base";

export class ViewGateGrant extends ViewBase<Access> implements GateGrantInterfaceWithPrimary<{}> {
  private static instance: ViewGateGrant;
  static getInstance(options?: { isSingleton?: boolean }) {
    if (options?.isSingleton === false) {
      return new ViewGateGrant();
    }

    if (!this.instance) this.instance = new ViewGateGrant();
    return this.instance;
  }

  private constructor() {
    super();
    this.initial();
    this.insertDefaultCondition();
  }

  async doVoucherGroupGrant(dto: doRiverVoucherGroupGrantDto) {
    const path = `${GateGrantGateway.path}/river/voucher/group`;
    return this.$request.put<doRiverVoucherGroupGrantDto, Access>(path, dto);
  }

  async doTonOrderGroupGrant(dto: doRiverTonOrderGroupGrantDto) {
    const path = `${GateGrantGateway.path}/river/ton-order/group`;
    return this.$request.put<doRiverTonOrderGroupGrantDto, Access>(path, dto);
  }

  async doStockeGrant(dto: doRiverStockeGrantDto) {
    const path = `${GateGrantGateway.path}/river/stock`;
    return this.$request.put<doRiverStockeGrantDto, Access>(path, dto);
  }
}
